package io.zw.modules.xinpai.controller;

import java.util.Arrays;
import java.util.Map;

import io.zw.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.zw.modules.xinpai.entity.UserProjectEntity;
import io.zw.modules.xinpai.service.UserProjectService;
import io.zw.common.utils.PageUtils;
import io.zw.common.utils.R;



/**
 * 
 *
 * @author zhuwei
 * @email 121203654@qq.com
 * @date 2018-10-13 14:00:30
 */
@RestController
@RequestMapping("xinpai/userproject")
public class UserProjectController {
    @Autowired
    private UserProjectService userProjectService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("xinpai:userproject:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userProjectService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userProjectId}")
    @RequiresPermissions("xinpai:userproject:info")
    public R info(@PathVariable("userProjectId") Integer userProjectId){
        UserProjectEntity userProject = userProjectService.selectById(userProjectId);

        return R.ok().put("userProject", userProject);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("xinpai:userproject:save")
    public R save(@RequestBody UserProjectEntity userProject){
        userProjectService.insert(userProject);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("xinpai:userproject:update")
    public R update(@RequestBody UserProjectEntity userProject){
        ValidatorUtils.validateEntity(userProject);
        userProjectService.updateAllColumnById(userProject);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("xinpai:userproject:delete")
    public R delete(@RequestBody Integer[] userProjectIds){
        userProjectService.deleteBatchIds(Arrays.asList(userProjectIds));

        return R.ok();
    }

}
